class MessagesController < InnerApplicationController
  
  def index
    @messages = @project.messages.all(:order => "created_at DESC")
  end

  def show
    @message = @project.messages.find(params[:id])
  end

  def new
    @message = @project.messages.new
  end
  
  def edit
    @message = @project.messages.find(params[:id])
  end

  def create
    @message = @project.messages.new(params[:message])
    @message.author = current_user
    
    if @message.save
      flash[:success] = "Message was successfully created."
      redirect_to project_message_url(@project, @message)
    else
      render :action => "new"
    end
  end
  
  def update
    @message = @project.messages.find(params[:id])
    
    if @message.update_attributes(params[:message])
      flash[:success] = 'Message was successfully updated.'
      redirect_to project_message_url(@project, @message)
    else
      render :action => "edit"
    end
  end
  
  def destroy
    @message = @project.messages.find(params[:id])
    @message.destroy
  end
end
